<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>芋头明 - 生活管理 - 消费记录</title>
		<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1.0, user-scalable=no">
		<meta name="description" content="">
		<meta name="keywords" content="">
		
		<%@ include file="/WEB-INF/views/common/base.jspf" %>
		<link rel="shortcut icon" href="${ctx}/favicon.ico" type="image/x-icon" />
		<!-- basic styles -->
		<link href="${ctx}/assets/common/plugin/ace/css/bootstrap.min.css" rel="stylesheet" />
		<link href="${ctx}/assets/common/plugin/ace/css/font-awesome.min.css" rel="stylesheet" />
		<link href="${ctx}/assets/common/plugin/select2/css/select2.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="${ctx}/assets/common/plugin/jedate/skin/jedate.css"/>
		<!--[if IE 7]>
		  <link rel="stylesheet" href="${ctx}/assets/common/plugin/ace/css/font-awesome-ie7.min.css" />
		<![endif]-->
		<!-- page specific plugin styles -->

		<!-- fonts -->

		<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />

		<!-- ace styles -->

		<link rel="stylesheet" href="${ctx}/assets/common/plugin/ace/css/ace.min.css" />
		<link rel="stylesheet" href="${ctx}/assets/common/plugin/ace/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="${ctx}/assets/common/plugin/ace/css/ace-skins.min.css" />
		<style>
			.span6 {
				float: left
			}
			#previousNext li {
				list-style-type:none;
				float: left
			}
		</style>
		
<%-- 		<link rel="stylesheet" href="${ctx}/assets/common/plugin/datepicker/css/bootstrap-datetimepicker.min.css"/> --%>

		<!--[if lte IE 8]>
		  <link rel="stylesheet" href="${ctx}/assets/common/plugin/ace/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->

		<script src="${ctx}/assets/common/plugin/ace/js/ace-extra.min.js"></script>

		<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

		<!--[if lt IE 9]>
		<script src="${ctx}/assets/common/plugin/ace/js/html5shiv.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>
		<%@ include file="/WEB-INF/views/admin/common/head-nav.jspf" %>

		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				<div class="sidebar" id="sidebar">
					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'fixed')}catch(e){}
					</script>

					<div class="sidebar-shortcuts" id="sidebar-shortcuts">
						<div class="sidebar-shortcuts-large" id="sidebar-shortcuts-large">
							<button class="btn btn-success">
								<i class="icon-signal"></i>
							</button>

							<button class="btn btn-info">
								<i class="icon-pencil"></i>
							</button>

							<button class="btn btn-warning">
								<i class="icon-group"></i>
							</button>

							<button class="btn btn-danger">
								<i class="icon-cogs"></i>
							</button>
						</div>

						<div class="sidebar-shortcuts-mini" id="sidebar-shortcuts-mini">
							<span class="btn btn-success"></span>

							<span class="btn btn-info"></span>

							<span class="btn btn-warning"></span>

							<span class="btn btn-danger"></span>
						</div>
					</div><!-- #sidebar-shortcuts -->

					<ul class="nav nav-list" id="tree-menu">
						<li class="active">
							<a href="index.html">
								<i class="icon-dashboard"></i>
								<span class="menu-text"> 控制台 </span>
							</a>
						</li>
					</ul><!-- /.nav-list -->

					<div class="sidebar-collapse" id="sidebar-collapse">
						<i class="icon-double-angle-left" data-icon1="icon-double-angle-left" data-icon2="icon-double-angle-right"></i>
					</div>

					<script type="text/javascript">
						try{ace.settings.check('sidebar' , 'collapsed')}catch(e){}
					</script>
				</div>

				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="#">首页</a>
							</li>
							<li class="active">控制台</li>
						</ul><!-- .breadcrumb -->

						<div class="nav-search" id="nav-search">
							<form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
							</form>
						</div><!-- #nav-search -->
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1>
								生活管理
								<small>
									<i class="icon-double-angle-right"></i>
									 消费记录
								</small>
							</h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->
								<div class="row" style="margin-bottom: 20px" id="operateToolBar">
									<div class="col-lg-2">
										<button data-toggle="modal" onclick="showAddDialog()" type="button" class="btn btn-primary">新增</button>
										<button data-toggle="modal" onclick="showEditDialog()" type="button" class="btn btn-primary">编辑</button>
	
										<div class="modal fade" tabindex="-1" role="dialog" id="orderModal" >
											<div class="modal-dialog" role="document">
												<div class="modal-content">
													<div class="modal-header">
														<button type="button" class="close" data-dismiss="modal" aria-label="Close">
															<span aria-hidden="true">&times;</span>
														</button>
														<h4 class="modal-title" id="orderModalLabel">新增消费记录</h4>
													</div>
													<div class="modal-body">
	
														<form id="submitForm" class="form-horizontal" action="${ctx}/admin/daily/order/add.html" onsubmit="return false;">
															<input id="order_dailyOrderId" name="dailyOrderId" type="hidden">
															<div class="form-group">
																<label for="consumeUserId" class="col-sm-2 control-label">消费用户</label>
																<div class="col-sm-10">
																	<select name="consumeUserId" class="form-control" id="order_consumeUserId" >
																	</select>
																</div>
															</div>
															<div class="form-group">
																<label for="consumeType" class="col-sm-2 control-label">消费类别</label>
																<div class="col-sm-10">
																	<select name="consumeType" class="form-control" id="order_consumeType">
																	</select>
																</div>
															</div>
															<div class="form-group">
																<label for="consumeTime" class="col-sm-2 control-label">消费时间</label>
																<div class="col-sm-10">
																	<input type="text" class="form-control jedate-ymdhms" readonly name="consumeTime" id="order_consumeTime"/>
																</div>
															</div>
															<div class="form-group">
																<label for="" class="col-sm-2 control-label">消费金额</label>
																<div class="col-sm-10">
																	<input type="text" class="form-control" name="consumeMoney" id="order_consumeMoney"/>
																</div>
															</div>
															<div class="form-group">
																<label for="payeeUsername" class="col-sm-2 control-label">应收款方</label>
																<div class="col-sm-10">
																	<input type="text" class="form-control" name="payeeUsername" id="order_payeeUsername"/>
																</div>
															</div>
															<div class="form-group">
																<label for="remark" class="col-sm-2 control-label">消费备注</label>
																<div class="col-sm-10">
																	<textarea class="form-control" name="remark" id="order_remark"></textarea>
																</div>
															</div>
														</form>
	
													</div>
													<div class="modal-footer">
														<button type="button" id="cancelBtn" class="btn btn-default" data-dismiss="modal">取消</button>
														<button type="submit" id="submitBtn" class="btn btn-primary" onclick="submitFormClick(this)" >保存</button>
													</div>
												</div>
											</div>
										</div>
	
										<button onclick="deleteOrder()" type="button" class="btn btn-primary">删除</button>
									</div>
									<div class="col-lg-3">
										<div class="form-group">
											<label for="search_userCode" class="col-sm-2 control-label">用户：</label>
											<div class="col-sm-10">
												<input id="search_userCode" name="userCode" type="text" class="form-control" placeholder="输入用户名或者账号进行搜索...">
											</div>
										</div>
										<!-- /input-group -->
									</div>
									<div class="col-lg-3">
										<div class="form-group">
											<label for="search_consumeType" class="col-sm-2 control-label">类型：</label>
											<div class="col-sm-10">
												<select class="form-control" id="search_consumeType" name="consumeType">
												</select>
											</div>
										</div>
										<!-- /input-group -->
									</div>
									<div class="col-lg-3">
										<div class="form-group">
											<label for="search_consumeTime" class="col-sm-2 control-label">时间：</label>
											<div class="col-sm-10">
												<input type="text" readonly class="form-control jedate-ymd" id="search_consumeTime" name="consumeTime">
											</div>
										</div>
										<!-- /input-group -->
									</div>
									<div class="col-lg-1">
										<div class="form-group">
											<div class="col-sm-12">
												<button class="btn btn-info" type="button" style="height: 36px" onclick="search(1)" onkeypress="Enter()">
													<i class="icon-ok bigger-110"></i>
													搜索
												</button>
											</div>
										</div>
										<!-- /input-group -->
									</div>
								</div>
								<!-- /.row -->
								
								
								<div class="panel panel-info">
									<div class="panel-heading">订单记录详情</div>
									<table class="table table-striped table-bordered table-hover datatable">
										<thead>
											<tr>
												<th><input id="checkAll" type="checkbox"/></th>
												<th>订单号</th>
												<th>消费者</th>
												<th>应收款方</th>
												<th>消费类型</th>
												<th>消费金额</th>
												<th>消费时间</th>
												<th>当前状态</th>
												<th>备注</th>
											</tr>
										</thead>
										<tbody id="table">
											
										</tbody>
									</table>
								</div>
								
								<!-- 页面底部显示 -->
								<!-- 每页显示几条记录 -->
								<div id="bottomTool" class="row-fluid">
									<div class="span6" style="width: 25%;; margin-right: 10px;">
										<div class="dataTables_length" id="DataTables_Table_0_length">
											<label> 每页 
												<select id="pageSize" onchange="research()" aria-controls="DataTables_Table_0" size="1" name="DataTables_Table_0_length">
													<option value="5">5</option>
													<option selected="selected" value="10">10</option>
													<option value="15">15</option>
													<option value="20">20</option>
												</select> 条记录
											</label>
										</div>
									</div>
									<!-- 显示第 1 至 10 项记录，共 57 项 -->
									<div class="span6" style="width: 35%;">
										<div id="DataTables_Table_0_info" class="dataTables_info">显示第1 至 10 项记录，共 57 项</div>
									</div>
									<!-- 第2页 -->
									<div class="span6" style="width: 30%;">
										<ul id="previousNext">
											<li onclick="previous()" class="prev disabled">
												<a style="text-decoration: none" id="previousPage" href="#">← 上一页 </a>
											</li>
											<div id="page" style="float: left;">
												<select id="pageNum" onchange="search()" style="width: 60px; margin-right: 1px;" aria-controls="DataTables_Table_0" size="1" name="DataTables_Table_0_length">
													<option selected="selected" value="1">1</option>
												</select>
											</div>
											<li class="next" onclick="next()">
												<a style="text-decoration: none" id="nextPage" href="#"> 下一页→ </a>
											</li>
										</ul>
									</div>
								</div>
									
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div><!-- /.main-content -->

				<div class="ace-settings-container" id="ace-settings-container">
					<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
						<i class="icon-cog bigger-150"></i>
					</div>

					<div class="ace-settings-box" id="ace-settings-box">
						<div>
							<div class="pull-left">
								<select id="skin-colorpicker" class="hide">
									<option data-skin="default" value="#438EB9">#438EB9</option>
									<option data-skin="skin-1" value="#222A2D">#222A2D</option>
									<option data-skin="skin-2" value="#C6487E">#C6487E</option>
									<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
								</select>
							</div>
							<span>&nbsp; 选择皮肤</span>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar" />
							<label class="lbl" for="ace-settings-navbar"> 固定导航条</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar" />
							<label class="lbl" for="ace-settings-sidebar"> 固定滑动条</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs" />
							<label class="lbl" for="ace-settings-breadcrumbs">固定面包屑</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl" />
							<label class="lbl" for="ace-settings-rtl">切换到左边</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container" />
							<label class="lbl" for="ace-settings-add-container">
								切换窄屏
								<b></b>
							</label>
						</div>
					</div>
				</div><!-- /#ace-settings-container -->
			</div><!-- /.main-container-inner -->

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="icon-double-angle-up icon-only bigger-110"></i>
			</a>
		</div><!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->

		<script src="${ctx}/assets/common/plugin/ace/js/jquery-2.0.3.min.js"></script>

		<!-- <![endif]-->

		<!--[if IE]>
			<script src="${ctx}/assets/common/plugin/ace/js//1.10.2/jquery.min.js"></script>
		<![endif]-->

		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='${ctx}/assets/common/plugin/ace/js/jquery-2.0.3.min.js'>"+"<"+"script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
			<script type="text/javascript">
			 window.jQuery || document.write("<script src='${ctx}/assets/common/plugin/ace/js/jquery-1.10.2.min.js'>"+"<"+"script>");
			</script>
		<![endif]-->

		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='${ctx}/assets/common/plugin/ace/js/jquery.mobile.custom.min.js'>"+"<"+"script>");
		</script>
		<script src="${ctx}/assets/common/plugin/ace/js/bootstrap.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->

		<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
		<![endif]-->

		<script src="${ctx}/assets/common/plugin/ace/js/jquery-ui-1.10.3.custom.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/jquery.ui.touch-punch.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/jquery.slimscroll.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/flot/jquery.flot.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/flot/jquery.flot.pie.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/flot/jquery.flot.resize.min.js"></script>
		<script src="${ctx}/assets/common/plugin/datepicker/js/bootstrap-datetimepicker.min.js"></script>
		<script src="${ctx}/assets/common/plugin/datepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
		<script src="${ctx}/assets/common/plugin/select2/js/select2.min.js"></script>
		<script src="${ctx}/assets/common/plugin/select2/js/i18n/zh-CN.js"></script>
		<script src="${ctx}/assets/common/plugin/layer/layer.js"></script>
		<script src="${ctx}/assets/common/plugin/jedate/jquery.jedate.min.js"></script>

		<!-- ace scripts -->

		<script src="${ctx}/assets/common/plugin/ace/js/ace-elements.min.js"></script>
		<script src="${ctx}/assets/common/plugin/ace/js/ace.min.js"></script>

		<!-- inline scripts related to this page -->

		<script src="${ctx}/assets/common/js/commonMethods.js"></script>
		<script>
			var _permissions = "${permissions}".replace(/ /g,'').replace('[','').replace(']','').split(',');
			function _hasPermission(p) {
				return $.inArray(p,_permissions) != -1;
			}
			ajaxAsyncRequest("{pid: '0'}", "/admin/sys/menu/tree", "POST", "json", initTreeMenu);
			function initTreeMenu(data) {
				var $tree = $("#tree-menu");
				for(var i = 0; i < data.length; i++) {
					var $li = $("<li></li>");
					var o = data[i];
					if(_hasPermission(o.id)){
						var a = '';
						a += '	<a href="${ctx}/admin/' + o.url + '.html" class="dropdown-toggle">';
						a += '		<i class="' + o.iconCls + '"></i>';
						a += '		<span class="menu-text"> ' + o.text + ' </span>';
						a += '		<b class="arrow icon-angle-down"></b>';
						a += '	</a>';
						var $a = $(a);
						$li.append($a);
						if(o.children != null) {
							var $ul = $('<ul class="submenu"></ul>');
							for(var j = 0; j < o.children.length; j++) {
								var p = o.children[j];
								var li = '';
								li += '<li>';
								li += '	<a href="${ctx}/admin/' + p.url + '.html">';
								li += '		<i class="icon-double-angle-right"></i>';
								li += '		' + p.text;
								li += '	</a>';
								li += '</li>';
								var $li1 = $(li);
								$ul.append($li1);
							}
							$li.append($ul);
						}
					}
					$tree.append($li);
				}
			}
		</script>
		<script>

			$.fn.modal.Constructor.prototype.enforceFocus = function () { }
			ajaxAsyncRequest("", "/admin/sys/user/all", "POST", "json", initUsers);
			ajaxSynchRequest("{staticType:'consumeType'}", "/admin/sys/static/list", "POST", "json", initConsumeType);
			function initUsers(data) {
				$("#order_consumeUserId").select2({
					language: "zh-CN",
					placeholder:'请选择',
					width: '100%'
				});
				for(var i = 0; i < data.length; i++) {
					var s = "<option value='" + data[i].userId + "'>" + data[i].userName + "</option>"
					$("#order_consumeUserId").append(s);
				}
			}
			function initConsumeType(data) {
				$("#search_consumeType").select2({
					language: "zh-CN",
					placeholder:'请选择',
					width: '100%'
				});
				$("#order_consumeType").select2({
					language: "zh-CN",
					placeholder:'请选择',
					width: '100%'
				});
				for(var i = 0; i < data.length; i++) {
					var s = "<option value='" + data[i].staticKey + "'>" + data[i].staticValue + "</option>"
					$("#search_consumeType").append(s);
					$("#order_consumeType").append(s);
				}
			}
			function editOrder() {
				
			}
			function getUrlParam(name) {
				var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) {
					return unescape(r[2]); 
				} else {
					return null;
				}
			}
			$(function() {
				var msg = getUrlParam("msg");
				if(msg == "updateRepeat") {
					layer.alert('存在重复的数据，修改失败', {
						icon: 2,
					  	skin: 'layer-ext-moon'
					});
				} else if (msg == "insertRepeat") {
					layer.alert('存在重复的数据，新增失败', {
						icon: 2,
					  	skin: 'layer-ext-moon'
					});
				}
			})
			
			$('#checkAll').click(function(){ 
			    $('input[name="subBox"]').attr("checked",this.checked); 
			});
			function operateOrderCallBack(data, text) {
				if(data.msg == "success") {
					layer.alert(text + '成功', {
						icon: 1,
					  	skin: 'layer-ext-moon'
					});
					if(text == "新增") {
						search(1);
						prependToTable(data.obj);
						$("#table").children("tr:last-child").remove();
						$("#cancelBtn").click();
					} else if(text == "修改") {
						var td = $("#table tr td:nth-child(2)");
						for(var i = 0; i < td.length; i++) {
							if($(td[i]).data("dailyorderid") == $("#order_dailyOrderId").val()) {
								var $tr = $(td[i]).parent(); 
								var tds = $tr.find("td");
								$(tds[2]).html($("#order_consumeUserId").text());
								$(tds[3]).html($("#order_payeeUsername").val());
								$(tds[4]).html($("#order_consumeType").text());
								$(tds[5]).html($("#order_consumeMoney").val());
								$(tds[6]).html($("#order_consumeTime").val());
								$(tds[8]).html($("#order_remark").val());
								$("#submitBtn").html("修改");
								break;
							}
						}
						$("#cancelBtn").click();
					} else if(text == "删除") {
						search();
					}
				} else if(data.msg == "failed") {
					layer.alert(text + '失败，已经存在这条数据', {
						icon: 2,
					  	skin: 'layer-ext-moon'
					});
				}
			}
			function submitFormClick(obj) {
// 				if(!validateName()) {
// 					return false;
// 				}
				var text = $(obj).text();
				var submitUrl;
				if(text == "新增") {
					submitUrl = "/admin/daily/order/add";
				} else if(text == "修改") {
					submitUrl = "/admin/daily/order/update";
				}
				var formData = getJsonStr("submitForm", "order_");
				ajaxAsyncRequest(formData, submitUrl, "POST", "json", operateOrderCallBack, text);
// 					error: function(data) {
// 						layer.alert(text + '失败，来自系统内部异常，可能是你的操作非法', {
// 							icon: 2,
// 						  	skin: 'layer-ext-moon'
// 						});
// 					}
			}
			function validateLengthTips(domSelector) {
				var name = $(domSelector).val();
				if(domSelector == "#name") {
					if(name == null || name.trim().length == 0) {
						layer.tips('敏感词不能为空', domSelector, {
							tips: [1, '#3595CC'],
							time: 1000
						});
						return false;
					}
				}
				if(name.trim().length > 10) {
					layer.tips('敏感词长度只能在10个字符以内', domSelector, {
						tips: [1, '#3595CC'],
						time: 1000
					});
					return false;
				}
				return true;
			}
			function validateName() {
				var name = $("#name").val();
				if(name == null || name.trim().length == 0) {
					layer.alert('敏感词不能为空', {
						icon: 2,
					  	skin: 'layer-ext-moon'
					});
					return false;
				}
				if(name.trim().length > 10) {
					layer.alert('敏感词长度只能在10个字符以内', {
						icon: 2,
					  	skin: 'layer-ext-moon'
					});
					return false;
				}
				return true;
			}
			
			function showDetail(obj) {
				$('#modalDialog').modal("show");
				$("#id").val($(obj).prev().text());
				$("#name").val($(obj).text());
				$("#level").val($(obj).next().text());
				$("#state").val($(obj).next().next().data("state"));
				$("#submitBtn").html("修改");
				$("#orderModalLabel").html("修改消费记录");
			}
			function showAddDialog() {
				$("#submitBtn").html("新增");
				$("#orderModalLabel").html("新增消费记录");
				$('#orderModal').modal("show");
				// 重置
				$("#submitForm")[0].reset();
			}
			function showEditDialog() {
				var checkBoxs = $("#table").find("input:checkbox:checked");
				var len = checkBoxs.length;
				if(len != 1) {
					layer.alert('你应该选择一条数据进行修改', {
						icon: 2,
					  	skin: 'layer-ext-moon'
					});
				} else {
					$('#orderModal').modal("show");
					var $tr = $(checkBoxs[0]).parent().parent(); 
					var tds = $tr.find("td");
					$("#order_dailyOrderId").val($(tds[1]).data("dailyorderid"));
					$("#order_consumeUserId").val($(tds[2]).data("consumeuserid"));
					$("#order_payeeUsername").val($(tds[3]).data("payeeusername"));
					$("#order_consumeType").val($(tds[4]).data("consumetype"));
					$("#order_consumeMoney").val($(tds[5]).data("consumemoney"));
					$("#order_consumeTime").val($(tds[6]).data("consumetime"));
					$("#order_remark").val($(tds[8]).data("remark"));
					$("#submitBtn").html("修改");
					$("#orderModalLabel").html("修改订单记录");
				}
			}
			function deleteOrder() {
				var ids = [];
				var subBox = $("#table").find('input[name="subBox"]');
				for(var i = 0; i < subBox.length; i++) {
					if($(subBox[i]).prop("checked")) {
						ids.push($(subBox[i]).parent().next().text());
					}
				}
				if(ids.length == 0) {
					layer.alert('你还没有选择想要删除的数据', {
						icon: 3,
					  	skin: 'layer-ext-moon'
					});
				} else {
					layer.confirm('您确定要删除选中数据吗？', {
						btn: ['确认','取消'] // 按钮
					}, function() {
						var value = "{ids: " + ids.join(",") + "}";
						ajaxAsyncRequest(value, "/admin/daily/order/delete", "POST", "json", operateOrderCallBack, "删除");
					}, function() {
						
					});
				}
			}
			
			//初始化，加载完成后执行
			window.onload = function() {
				search(1);
			};
			//搜索按钮绑定回车事件
			document.onkeydown = function(event) {
				if (event.keyCode == 13) {
					event.cancelBubble = true;
					event.returnValue = false;
					search(1);
				}
			}
			
			//下一步
			function next() {
				//得到当前选中项的页号
				var id = $("#pageNum option:selected").val();
				//计算下一页的页号
				var nextPage = parseInt(id) + 1;
				//得到select的option集合
				var list = document.getElementById("pageNum").options;
				//得到select中，下一页的option
				var nextOption = list[nextPage - 1];
				//修改select的选中项
				nextOption.selected = true;
				//调用查询方法
				search();
			}
			
			//上一步
			function previous() {
			
				//得到当前选中项的页号
				var id = $("#pageNum option:selected").val();
				//计算上一页的页号
				var previousPage = parseInt(id) - 1;
				//得到select的option集合
				var list = document.getElementById("pageNum").options;
				//得到select中，上一页的option
				var previousOption = list[previousPage - 1];
				//修改select的选中项
				previousOption.selected = true;
				
				//调用查询方法
				search();
			}
			
			//修改每页显示条数时，要从第一页开始查起
			function research() {
				//得到select的option集合
				var list = document.getElementById("pageNum").options;
				//得到select中，第一页的option
				var nextOption = list[0];
				//修改select的选中项
				nextOption.selected = true;
				//调用查询方法
				search();
			}
			
			
			function searchOrderCallback(data) {
				//得到结果集
				var obj = data.list;
				//将除模板行的thead删除，即删除之前的数据重新加载 
				$("#table").children().remove();
	
				if(obj.length == 0) {
					var tr = $("<tr><td style='text-align: center' colspan='9'>暂无数据</td></tr>");
					tr.appendTo("#table");
				}
	
				//将获取到的数据动态的加载到table中 
				for (var i = 0; i < obj.length; i++) {
					appendToTable(obj[i]);
				}
				//当前记录总数
				var pageNumCount = data.allRecords;
				//当前记录开始数
				var pageNumBegin = (obj.pageNo - 1) * obj.pageSize + 1;
				//当前记录结束数
				var pageNumEnd = obj.pageNum * obj.pageSize
				//如果结束数大于记录总数，则等于记录总数
				if (pageNumEnd > pageNumCount) {
					pageNumEnd = pageNumCount;
				}
				//得到总页数
				var pageCount;
				if (pageNumCount / pageSize == 0) {
					pageCount = pageNumCount / pageSize;
				} else {
					pageCount = Math.ceil(pageNumCount / pageSize);
				}
	
				//输出"显示第 1 至 10 项记录，共 57 项"
				document.getElementById("DataTables_Table_0_info").innerHTML = "显示第"
						+ pageNumBegin.toString()
						+ " 至 "
						+ pageNumEnd.toString()
						+ " 项记录，共 "
						+ pageNumCount.toString() + " 项";
	
				//显示所有的页码数
				var pageSelect = document.getElementById("page");
				var pageOption = "";
				var flag;
				//删除select下所有的option，清除所有页码
				document.getElementById("pageNum").options.length = 0;
				for (var i = 0; i < pageCount; i++) {
					flag = (i + 1).toString();
					var option;
					//如果等于当前页码
					if (flag == pageNum) {
						//实例化一个option,则当前页码为选中状态
						option = new Option(flag, flag, false, true);
					} else {
						option = new Option(flag, flag, false,
								false);
					}
					//将option加入select中
					document.getElementById("pageNum").options
							.add(option);
				}
	
				//如果总记录数小于5条，则不显示分页
				if ((pageNumCount - 5) < 0) {
					document.getElementById("bottomTool").style.display = "none";
				} else {
					document.getElementById("bottomTool").style.display = "";
				}
	
				/**给上一步下一步加颜色**/
				//判断是否只有一页
				if (pageCount == 1) {
	
					//如果只有一页，上一步，下一步都为灰色
					$("#previousPage").css("color", "#AAA");//给上一步加灰色
					$("#nextPage").css("color", "#AAA");//给下一步加灰色
				} else if (pageNum - 1 < 1) {
					//如果是首页,则给上一步加灰色，下一步变蓝
					$("#previousPage").css("color", "#AAA");//给上一步加灰色
					$("#nextPage").css("color", "#00F");//给下一步加蓝色
				} else if (pageNum == pageCount) {
					//如果是尾页,则给上一步加蓝色，下一步灰色
					$("#previousPage").css("color", "#00F");//给上一步标签加蓝色
					$("#nextPage").css("color", "#AAA");//给下一步标签加灰色
				} else {
					//上一步为蓝色，下一步为绿色
					$("#previousPage").css("color", "#00F");//给上一步加蓝色
					$("#nextPage").css("color", "#4D9");//给下一步加绿色
				}
			}
			//搜索，模糊查询敏感词
			function search(pageNum) {
				var formData = getJsonStr("operateToolBar", "search_");
				//得到每页显示条数
				var pageSize = $("#pageSize").val();
				if(!pageNum) {
					//得到显示第几页
					pageNum = $("#pageNum").val();
				}
				var obj = eval('(' + formData + ')');
				if(!obj) {
					obj = {};
				}
				obj.pageSize = pageSize;
				obj.pageNum = pageNum;
				var value = JSON.stringify(obj);

				ajaxAsyncRequest(value, "/admin/daily/order/page", "POST", "json", searchOrderCallback);
			}
			//向后追加，前面一个参数是要追加的对象，后面一个参数是追加的位置，prepend和append
			function writeToTable(obj, position) {
				var tr = $("<tr></tr>");
				var td0 = $("<td data-tag='check'><input name='subBox' type='checkbox'/></td>");
				var td1 = $("<td data-dailyOrderId='" + obj.dailyOrderId + "'>" + obj.dailyOrderNo + "</td>");
				var td2 = $("<td title='点击进行修改' style='cursor: pointer' onclick='showDetail(this)' data-consumeUserName='" + obj.consumeUserName + "'>" + obj.consumeUserName + "</td>");
				var td3 = $("<td data-payeeUsername='" + obj.payeeUsername + "'>" + obj.payeeUsername + "</td>");
				var td4 = $("<td data-consumeType='" + obj.consumeType + "'>" + obj.consumeTypeName + "</td>");
				var td5 = $("<td data-consumeMoney='" + obj.consumeMoney + "'>" + obj.consumeMoney + "</td>");
				var dateFormat = (new Date(obj.consumeTime)).format("yyyy-MM-dd HH:mm:ss");
				var td6 = $("<td data-consumeTime='" + dateFormat + "'>" + dateFormat + "</td>");
				var stateText = obj.isPay == 1 ? "已结清" : obj.isPay == 0 ? "未支付" : "未知状态";
				var td7 = $("<td data-isPay='" + obj.isPay + "'>" + stateText + "</td>");
				var td8 = $("<td data-remark='" + obj.remark + "'>" + obj.remark + "</td>");
				
				tr.append(td0).append(td1).append(td2).append(td3).append(td4).append(td5).append(td6).append(td7).append(td8);
				//将新行添加到表格中 
				if(position == "append") {
					tr.appendTo("#table");
				} else if(position == "prepend") {
					tr.prependTo("#table");
				}
			}
			function appendToTable(obj) {
				writeToTable(obj, "append");
			}
			function prependToTable(obj) {
				writeToTable(obj, "prepend");
			}
		</script>
	</body>
</html>